﻿using System;
using System.IO;
using System.Windows.Forms;
using ShortcutToolbox.View;
using ShortcutToolbox.Controller;
using ShortcutToolbox.Core;

namespace ShortcutToolbox
{
    static class Program
    {
        static MainController controller;

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Directory.SetCurrentDirectory(Application.StartupPath);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            dynamic lang = I18N.Current;
            if (lang == null)
            {
                MessageBox.Show("No language file", "Error");
                return;
            }

            if (!Logging.OpenLogFile())
            {
                MessageBox.Show(
                    I18N.Current.Errors.AccessFile.ToString().Replace("{$file_path}", Logging.LogFilePath),
                    I18N.Current.Errors.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            controller = new MainController();
            MenuViewController viewController = new MenuViewController(controller);
            controller.Start();
            Application.ApplicationExit += Application_ApplicationExit;
            Application.Run();
        }

        private static void Application_ApplicationExit(object sender, EventArgs e)
        {
            if (controller != null)
            {
                controller.Stop();
                controller = null;
            }
        }

    }
}
